package org.yi.fc.entity;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Preconditions;
import com.jfinal.plugin.activerecord.Model;

public class FPermission extends Model<FPermission>{

	private static final long serialVersionUID = 1L;
	
	private Logger logger = LoggerFactory.getLogger(getClass());
	
	public static FPermission dao = new FPermission();
	
	/**
	 * 根据用户id获取该用户创建的所有权限
	 * @param id
	 * @return
	 */
	public List<FPermission> getRolesByCreateUserId(int id){
		logger.debug("call getRolesByCreateUserId('{}'),【id={}】",id,id);
		String sql = "select * from f_role_permission where crate_user_id = ?";
		return find(sql, id);
	}
	
	/**
	 * 根据权限的主键数组获取权限列表
	 * @param ids
	 * @return
	 */
	public List<FPermission> getRolesByIds(int [] ids){
		Preconditions.checkNotNull(ids,"根据角色的主键数组获取角色列表时，主键数组不能weikong");
		StringBuffer sql = new StringBuffer("select * from f_role_permission where id in (");
		for(int id : ids){
			sql.append(id).append(",");
		}
		sql.setCharAt(sql.length() - 1, ' ');
		sql.append(")");
		
		List<FPermission> permissions = find(sql.toString());
		return permissions;
	}
	
}
